import sample from "./sample.json";
import axios from "axios";
const btnMethods = {
    renderLocal() {
        console.log(1111);
        if (this.json === null) {
            this.json = sample;
            console.log("Home-local", this.json);
            this.fixNodesPosition();
            this.$nextTick(() => this.init());
            this.$message.success("render success!");
        } else this.$message.warning("render duplication!");
    },
    renderAPI() {
        if (this.json !== null) this.clear();
        let msg = this.$message.loading({
            content: "Loading...",
            duration: 0,
        });
        setTimeout(msg, 2500);
        axios
            .get(this.requestURL)
            .then((response) => {
                if (response.status === 200) {
                    this.json = response.data;
                    this.fixNodesPosition();
                    this.$nextTick(() => this.init());
                    this.$message.success("render success!");
                }
            })
            .catch((error) => {
                console.log(error);
                this.$message.error("render error!");
            });
    },
    clear() {
        console.log("clear");
        if (
            Object.keys(this.json).length &&
            Object.keys(this.json.nodes).length
        ) {
            this.jsPlumb.deleteEveryConnection();
            this.jsPlumb.deleteEveryEndpoint();
            this.json.nodes.forEach((node) => {
                this.jsPlumb.remove(node.id);
            });
        }
        this.json = null;
    },
}
export default btnMethods